package com.lp.multi.thread.example04;

/**
 * @author: lp
 * @create: 2021-06-21 8:46
 * @description: TODO
 */
public class TicketThread implements Runnable{
    private int ticketNums =50;
    @Override
    public void run() {
        while (true){
            synchronized (TicketThread.class){
                if(ticketNums <= 0){
                    break;
                }
                System.out.println("线程"+Thread.currentThread().getName()+"拿到了第" + ticketNums-- +"张票");
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        TicketThread ticketThread = new TicketThread();
        new Thread(ticketThread,"小明").start();
        new Thread(ticketThread,"老师").start();
        new Thread(ticketThread,"黄牛").start();

    }
}
